package test_achieve.web;

import constant.Constant;
import constant.WebCityId;
import cucumber.api.PendingException;
import cucumber.api.java.en.Given;
import org.junit.Assert;
import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
import util.tools.BusinessTools;
import util.tools.CommonTools;

import java.math.BigDecimal;
import java.net.UnknownHostException;

/**
 * Created by lenovo on 2018/5/17.
 */
public class Invoice {
    private  BigDecimal InvoiceMoney;//可开发票金额
    private BigDecimal InvoiceMoneyTure= new BigDecimal(0);

    @Given("^w进入到申请发票菜单中$")
    public void w进入到申请发票菜单中() throws Throwable {
        OrderMain orderMain = new OrderMain();
        orderMain.w进入我的闪送中();
        Constant.driverWeb.findElement(By.xpath("//*[@id=\"container_wrapper\"]/div[1]/div[1]/dl[2]/dd[5]/a")).click();//点击申请发票
    }

    @Given("^w获取可申请发票的金额：(.*)$")
    public void w获取可申请发票的金额(String city) throws Throwable {
        BusinessTools.menuCityChoice(city);
         String InvoiceMoney = Constant.driverWeb.findElement(By.xpath("//*[@id=\"app\"]/div/div/div[2]/div[2]/div/div[3]/span[2]")).getText();//获取可申请发票金额
        this.InvoiceMoney = new BigDecimal(InvoiceMoney);//订单总额
    }

    @Given("^w确认可开票金额$")
    public void w确认可开票金额() throws Throwable {
        System.out.println("this.InvoiceMoney:"+this.InvoiceMoney);
        BigDecimal OrderAmount = new BigDecimal(Constant.orderAmount);//订单总额
        System.out.println("订单总额："+OrderAmount);

        String money = OrderAmount.add(InvoiceMoney).subtract(this.InvoiceMoneyTure).toString();//计算当前发票金额
        Thread.sleep(4000);
        String pageMoney =Constant.driverWeb.findElement(By.xpath("//*[@id=\"app\"]/div/div/div[2]/div[2]/div/div[3]/span[2]")).getText();
        Assert.assertEquals(money,pageMoney);
    }

    @Given("^w点击立即申请$")
    public void w点击立即申请() throws Throwable {
        Constant.driverWeb.findElement(By.xpath("//*[@id=\"app\"]/div/div/div[2]/div[2]/div/div[3]/div[1]")).click();//点击立即申请
    }

    @Given("^w那么可以正常显示发票申请页面$")
    public void w那么可以正常显示发票申请页面() throws Throwable {
        String adc = Constant.driverWeb.findElement(By.xpath("//*[@id=\"app\"]/div/div/div[2]/div[2]/div/div[3]/form/div[8]/button")).getText();
        Assert.assertEquals(adc,"确认申请");
    }

    @Given("^w选择开票纸质发票$")
    public void w选择开票纸质发票() throws Throwable {
      Constant.driverWeb.findElement(By.xpath("//*[@id=\"app\"]/div/div/div[2]/div[2]/div/div[3]/form/div[2]/div/div/button[2]")).click();//点击纸质发票
    }

    @Given("^w填写纸质发票内容：<申请金额>：<收票人手机>$")
    public void w填写纸质发票内容(String invoiceValue,String invoiceTitle,String invoiceContent,String sendAdress,String sendName)throws Throwable {
        w输入发票金额(invoiceValue);
    }
    @Given("^w输入发票金额：(.*)$")
    public void w输入发票金额(String invoiceValue) throws Throwable {
        Constant.driverWeb.findElement(By.name("amount")).sendKeys(invoiceValue);
    }
    @Given("^w选择发票抬头$")
    public void w选择发票抬头() throws Throwable {
//        Constant.driverWeb.findElement(By.xpath())、、、、、、、、、、、、、、······································································

    }

//    @Given("^w填写纸质发票内容：<申请金额>：<收票人手机>$")
//    public void w填写纸质发票内容申请金额收票人手机() throws Throwable {
//        // Write code here that turns the phrase above into concrete actions
//        throw new PendingException();
//    }

    @Given("^w点击确认申请$")
    public void w点击确认申请() throws Throwable {
       Constant.driverWeb.findElement(By.xpath("//*[@id=\"app\"]/div/div/div[2]/div[2]/div/div[3]/form/div[8]/button")).click();

    }

    @Given("^w输入申请发票金额：(.*)$")
    public void w输入申请发票金额(String money) throws Throwable {
        BigDecimal money1 = new BigDecimal(money);
        this.InvoiceMoneyTure = money1.add(this.InvoiceMoneyTure);
        System.out.println("fuzhi1111"+this.InvoiceMoney);
       WebElement moneyElement = Constant.driverWeb.findElement(By.className("form-control"));
       moneyElement.clear();
       moneyElement.sendKeys(money);
    }

    @Given("^w发票抬头选择个人$")
    public void w发票抬头选择个人() throws Throwable {
        Constant.driverWeb.findElement(By.xpath("//*[@id=\"app\"]/div/div/div[2]/div[2]/div/div[3]/form/div[4]/div/div/label[1]/input")).click();
    }
    @Given("^w设置收件人所在区域$")
    public void w设置收件人所在区域() throws Throwable {
        Constant.driverWeb.findElement(By.xpath("//*[@id=\"app\"]/div/div/div[2]/div[2]/div/div[3]/form/div[6]/div[2]/div/div/div[1]/select[1]")).click();
        Constant.driverWeb.findElement(By.xpath("//*[@id=\"app\"]/div/div/div[2]/div[2]/div/div[3]/form/div[6]/div[2]/div/div/div[1]/select[1]/option[2]")).click();
        Constant.driverWeb.findElement(By.xpath("//*[@id=\"app\"]/div/div/div[2]/div[2]/div/div[3]/form/div[6]/div[2]/div/div/div[1]/select[2]")).click();
        Constant.driverWeb.findElement(By.xpath("//*[@id=\"app\"]/div/div/div[2]/div[2]/div/div[3]/form/div[6]/div[2]/div/div/div[1]/select[2]/option[2]")).click();
        Constant.driverWeb.findElement(By.xpath("//*[@id=\"app\"]/div/div/div[2]/div[2]/div/div[3]/form/div[6]/div[2]/div/div/div[1]/select[3]")).click();
        Constant.driverWeb.findElement(By.xpath("//*[@id=\"app\"]/div/div/div[2]/div[2]/div/div[3]/form/div[6]/div[2]/div/div/div[1]/select[3]/option[2]")).click();

    }

    @Given("^w填写收件人信息$")
    public void w填写收件人信息() throws Throwable {
        Constant.driverWeb.findElement(By.name("reqAddress")).sendKeys("博彦科技大厦");
        Constant.driverWeb.findElement(By.name("reqName")).sendKeys("徐辉");
        Constant.driverWeb.findElement(By.name("reqMobile")).sendKeys("15501213579");

    }

    @Given("^可以申请成功$")
    public void 可以申请成功() throws Throwable {
        Constant.driverWeb.findElement(By.xpath("//*[@id=\"app\"]/div/div/div[2]/div[2]/div/table/tbody/tr/td[5]/span/span[1]")).click();
    }
}
